// app/model/friends.js
"use strict";
module.exports = (app) => {
    const crypto = require('crypto');
    const { STRING, INTEGER, DATE, ENUM, TEXT } = app.Sequelize;
    // 配置（重要：一定要配置详细，一定要！！！）
    const LiveGift = app.model.define("live_gift", {
        id: {
            type: INTEGER(20),
            primaryKey: true,
            autoIncrement: true,
          },
          live_id: {
            type: INTEGER,
            allowNull: false,
            defaultValue: 0,
            comment: "直播间id",
            references: {
              model: "live",
              key: "id",
            },
            onDelete: "cascade",
            onUpdate: "restrict", // 更新时操作
          },
          user_id: {
            type: INTEGER,
            allowNull: false,
            defaultValue: 0,
            comment: "用户id",
            references: {
              model: "user",
              key: "id",
            },
            onDelete: "cascade",
            onUpdate: "restrict", // 更新时操作
          },
          gift_id: {
            type: INTEGER,
            allowNull: false,
            defaultValue: 0,
            comment: "礼物id",
            references: {
              model: "gift",
              key: "id",
            },
            onDelete: "cascade",
            onUpdate: "restrict", // 更新时操作
          },
          created_time:{
            type:DATE,

                get(){ 
            
                    return (app.formatTime(this.getDataValue("created_time")));
                }
              
          } ,
           updated_time: DATE,

    });
    LiveGift.associate = function (models) {
        LiveGift.belongsTo(app.model.User)
        LiveGift.belongsTo(app.model.Live)
        LiveGift.belongsTo(app.model.Gift)
    }
    return LiveGift;
};